<!DOCTYPE html>
<html lang="en-us">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  	<meta property="og:title" content=" 百度云技术--文字识别 &middot;  我的博客" />
  	<meta property="og:site_name" content="我的博客" />
  	<meta property="og:url" content="/my_technology/wenzishibie/" />
    
    
  	<meta property="og:type" content="article" />

    <meta property="og:article:published_time" content="2020-05-09T21:22:28&#43;08:00" />

    
    

  <title>
     百度云技术--文字识别 &middot;  我的博客
  </title>

    <meta name="description" content="这里是付佳康的个人博客" />

    <meta name="HandheldFriendly" content="True" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="shortcut icon" href="/my_technology/images/favicon.ico">
	  <link rel="apple-touch-icon" href="/my_technology/images/apple-touch-icon.png" />
    
    <link rel="stylesheet" type="text/css" href="/my_technology/css/screen.css" />
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400|Inconsolata" />


    
      
          <link href="/my_technology/index.xml" rel="alternate" type="application/rss+xml" title="我的博客" />
      
      
    
    <meta name="generator" content="Hugo 0.68.3" />

    <link rel="canonical" href="/my_technology/wenzishibie/" />

     
</head>
<body class="nav-closed">
<div id="particles-js"></div>
  


 <div class="site-wrapper">



<header class="main-header " style="background-image: url(/my_technology/images/user.jpg)">

    <nav class="main-nav overlay clearfix">
        
            <a class="blog-logo" href="/my_technology/"><img src="/my_technology/images/user.png" alt="Blog Logo" /></a>
        
        
    </nav>
<div class="vertical">
        <div class="main-header-content inner">
            <h1 class="page-title">
              <a class="btn-bootstrap-2" href="#content">我的博客</a>
          </h1>
          <h2 class="page-description">这里是付佳康的个人博客</h2>
        </div>
</div>
    <a class="scroll-down icon-arrow-left" href="#content"><span class="hidden">Scroll Down</span></a>
</header>

  <main id="content" class="content" role="main">


  <article class="post ">

    <header class="post-header">
        <h1 class="post-title">百度云技术--文字识别</h1>
        <section class="post-meta">
        
         
        </section>
    </header>

    <section class="post-content">
      <pre><code># 导包
import requests
import base64
import urllib

# 获取token
res = requests.get('https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&amp;client_id=4jvGHt81mnZ48nnGH0lwT0bG&amp;client_secret=72YiaT9GX0wwWfMUGSDl8FdUfP7Y1Sg4')

# print(res.json())

token = res.json()['access_token']
# print(token)

# 开始智能识图
# 接口地址
url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token='+token
# 定义头部信息
myheaders = {'Content-Type': 'application/x-www-form-urlencoded'}

# 操作图片
# 读取图片
myimg = open('./code.png', 'rb')
temp_img = myimg.read()
# 关闭图片
myimg.close()

# 进行base64编码
temp_data = {'image': base64.b64encode(temp_img)}

# 对图片地址进行urlencode操作
temp_data = urllib.parse.urlencode(temp_data)

# 请求识图接口
res = requests.post(url=url, data=temp_data, headers=myheaders)
print(res.json())
code = res.json()['words_result'][0]['words']

code = str(code).replace(' ', '')
print(code)

</code></pre>
    </section>


  <footer class="post-footer">


    
    <figure class="author-image">

        <a class="img" href="/my_technology/" style="background-image: url(/my_technology/images/user.png)"><span class="hidden">付佳康</span></a>
    </figure>
    

    <section class="author">

  <p>付佳康</p>
  

</section>


    
    <section class="share">
      <h4>Share this page</h4>
      <a class="icon-twitter" style="font-size: 1.4em" href="https://twitter.com/share?text=%e7%99%be%e5%ba%a6%e4%ba%91%e6%8a%80%e6%9c%af--%e6%96%87%e5%ad%97%e8%af%86%e5%88%ab&amp;url=%2fmy_technology%2fwenzishibie%2f"
          onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
          <span class="hidden">Twitter</span>
      </a>
      <a class="icon-facebook" style="font-size: 1.4em" href="https://www.facebook.com/sharer/sharer.php?u=%2fmy_technology%2fwenzishibie%2f"
          onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
          <span class="hidden">Facebook</span>
      </a>
      <a class="icon-google-plus" style="font-size: 1.4em" href="https://plus.google.com/share?url=%2fmy_technology%2fwenzishibie%2f"
         onclick="window.open(this.href, 'google-plus-share', 'width=490,height=530');return false;">
          <span class="hidden">Google+</span>
      </a>
    </section>
    

    
    
    

  </footer>
</article>

</main>
    <footer class="site-footer clearfix">
        <section class="copyright"><a href="">我的博客</a> </section>
        
        <section class="poweredby">Proudly generated by <a class="icon-hugo" href="https://gohugo.io">HUGO</a>, with <a class="icon-theme" href="https://github.com/syui/hugo-theme-air">hugo-theme-air</a> theme</section>
        
    </footer>
    </div>
    <script type="text/javascript" src="/my_technology/js/jquery.js"></script>
    <script type="text/javascript" src="/my_technology/js/jquery.fitvids.js"></script>
    <script type="text/javascript" src="/my_technology/js/index.js"></script>
    <script src="/my_technology/js/particles.min.js"></script>
    <script src="/my_technology/js/particles.js"></script>  

</body>
</html>

